import 'package:imperius_insights/entity/hr.dart';

import 'quality.dart';
import 'tech_asset.dart';

/// 项目状态
enum Staging {
  /// 未设置
  Unset,

  /// 已排期
  Scheduled,

  /// 开发中
  Develop,

  /// 自测中
  SelfTesting,

  /// 已提测
  PendingToTest,

  /// 测试中
  QATesting,

  /// 待发布
  PrePublish,

  /// 已发布
  PostPublish,

  /// 暂停
  Paused
}

class Project {
  /// 项目名称
  String name;

  /// 项目PMO号
  final String pmo;

  /// 项目优先级
  String priority;

  /// 项目JIRA链接
  String get linkJira => 'http://pmo.corp.qunar.com/browse/$pmo';

  /// 项目bug链接
  String get bugsLink => 'http://todolist.qunar.com/?pmoNumber=$pmo';

  /// 项目QT群
  String qtLink =
      'qunarchat/openSingleChat?jid=meng.jiang@ejabhost1&realJid=meng.jiang@ejabhost1';

  /// 项目所处阶段
  Staging staging;

  /// 开始开发时间
  DateTime startDevDate;

  /// 完成开发时间
  DateTime get endDevDate {
    if (type == '任务') {
      return endTestDate;
    }
    if (startTestDate == null) {
      return null;
    }
    final date = startTestDate?.subtract(Duration(days: 1));
    return date.isBefore(startDevDate) ? startDevDate : date;
  }

  /// 开始测试时间
  DateTime startTestDate;

  /// 类型
  String type;

  /// 结束测试时间
  DateTime get endTestDate => scheduledPublishDate;

  /// 计划发布时间
  DateTime scheduledPublishDate;

  /// 实际发布时间
  DateTime actualPublishDate;

  /// 项目责任人
  List<HumanDirector> humansOfDirector;

  /// 开发人员
  List<HumanRD> humansOfRD;

  /// QA人员
  List<HumanQA> humansOfQA;

  /// PM人员
  List<HumanPM> humansOfPM;

  /// 关联的技术资产
  List<TechAsset> techAssets;

  /// 开发过程数据
  QualityInDevelopment qualityInDevelopment;

  /// 自测过程数据
  QualityInRDTesting qualityInRDTesting;

  /// 测试质量数据
  QualityInQATesting qualityInQATesting;

  Project(
      {this.name,
      this.pmo,
      this.staging,
      this.qtLink,
      this.priority,
      this.startDevDate,
      this.startTestDate,
      this.scheduledPublishDate,
      this.actualPublishDate,
      this.humansOfDirector,
      this.humansOfRD,
      this.humansOfQA,
      this.humansOfPM,
      this.techAssets,
      this.qualityInDevelopment,
      this.qualityInRDTesting,
      this.qualityInQATesting});

  void parseStaging(String stagingText) {
    const map = {
      '需求待FR': Staging.Unset,
      '待定': Staging.Unset,
      '需求FR通过': Staging.Scheduled,
      '已排期': Staging.Scheduled,
      '开始': Staging.Scheduled,
      '进行中': Staging.Develop,
      '开发中': Staging.Develop,
      '开发完成': Staging.Develop,
      '已提测': Staging.PendingToTest,
      '测试中': Staging.QATesting,
      '待发布': Staging.PrePublish,
      '已关闭': Staging.PostPublish,
      '暂停': Staging.Paused,
    };
    this.staging = map[stagingText] ?? Staging.Unset;
    if (staging == Staging.Unset) {
      print(stagingText);
    }
  }
}
